package org.wu.reggie.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.wu.reggie.common.R;
import org.wu.reggie.entity.Orders;
import org.wu.reggie.service.OrderService;

import javax.servlet.http.HttpSession;

@Slf4j
@RequestMapping("/order")
@RestController
public class OrderController {


    @Autowired
    private OrderService orderService;

    @PostMapping("/submit")
    public R<String> submit(@RequestBody Orders orders, HttpSession session){

        // 1 得到登录者
        Long userId = (Long) session.getAttribute("user");
        // 2 下单
        orderService.submit(orders,userId);
        return R.success("下单成功");
    }

}
